// JavaScript Document
/* index.js by been 2012/02/25 */
;function init(){
		var height = $(window).height()-120;
		$(".left").height(height);//用$(document).height()-100 在IE下尺寸不对;
		$(".main").height(height).width($(window).width()-174);
		/*var liClick = getCookie("selected");
		if(liClick !="" || liClick!= null){
			alert(liClick);
			$("#"+liClick).addClass("selected").siblings().removeClass("selected");
			$('#skinCSS').attr("href","css/index/"+(liClick)+".css");
		}*/
	}
	function initMenu(){
		$(".menu li a").click(
			function(){
				var $checkElement = $(this).next();
				if($checkElement.is('ul') && $checkElement.is(':visible')){
					$checkElement.slideUp('normal');
					return false;//防止类似标签<a>的链接
				}
				if($checkElement.is('ul') && (!$checkElement.is(':visible'))){
					$('#menu ul:visible').slideUp('normal');
					$checkElement.slideDown('normal');
					return false;
				}
			}
		);
	}
		var timerID = null;
		var timerRunning = false;
		function stopclock (){
		  if(timerRunning)
		  clearTimeout(timerID);
		  timerRunning = false;
		}
		function startclock () {
		  stopclock();
		  showtime();
		}
		function showtime () {
		  var now = new Date();
		  var hours = now.getHours();
		  var minutes = now.getMinutes();
		  var seconds = now.getSeconds();
		  var timeValue = 0;
		  if($.browser.msie){
			  timeValue = now.getYear(); 
		  }else{
			  timeValue = now.getYear()+1900;
		  }
		  timeValue += "年"+(now.getMonth()+1)+"月"+now.getDate()+"日" +((hours >= 12) ? " 下午 " : " 上午 " ); 
		  timeValue += ((hours >12) ? hours -12 :hours);
		  timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
		  timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
		  $('.time').html("当前时间: "+timeValue);
		  timerID = setTimeout("showtime()",1000);
		  timerRunning = true;
		}
	
	function changeSkin(){
		$('.skin li').click(function(){
			var liClick="#"+this.id;
			if(!$(liClick).attr("class")){
				/*siblings() 找到其它同辈的元素*/
				$(liClick).addClass("selected").siblings().removeClass("selected");
				$('#skinCSS').attr("href","../css/index/"+(this.id)+".css");
				//setCookie("selected",this.id);
			}
		});
	}
	function setCookie(name,value){
		//var Days = 30; //此 cookie 将被保存 30 天
		// var exp = new Date();
		// exp.setTime(exp.getTime() + Days*24*60*60*1000);
		// document.cookie = name + "="+ escape(value) +";exp="+ exp.toGMTString();
	   document.cookie = name + "="+ escape(value);
	}
	function getCookie(name){
		var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
		alert(arr);
		if(arr != null) return unescape(arr[2]); return null;
	}
	function delCookies(name){
		// var exp = new Date();
		//exp.setTime(exp.getTime() - 1);
		var cval=getCookie(name);
		// if(cval!=null) document.cookie=name +"="+cval+";exp="+exp.toGMTString();;
		if(cval!=null) document.cookie=name +"="+cval;
	}
		
	$(function(){
		init();
		initMenu(); 
		startclock(); 
		changeSkin();
	});
	
	$(window).resize(function(){
		init();
	});